package com.exsun.gateway.jt809.kafka.gps;

import com.exsun.gateway.jt809.data.Interface.IGpsHandle;
import com.exsun.gateway.jt809.data.PushData;
import com.exsun.gateway.jt809.handler.SendMgrHandler;
import exsun.jt808.data.config.jt809.Jt809MsgIdConfig;
import exsun.jt808.data.jt809_data.BasicVehicleInfo;
import exsun.jt808.data.jt809_data.vehicledynamic.GnssData;
import exsun.jt808.data.jt809_data.vehicledynamic.main.UpExgMsgHistoryLocation;
import exsun.jt808.data.upload_data.GpsData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

public class HistoryLocation implements IGpsHandle<UpExgMsgHistoryLocation> {
    private Logger logger = LoggerFactory.getLogger(HistoryLocation.class);
    /**
     * 组包
     * @param data
     * @param sendMgrHandler
     * @return
     */
    @Override
    public List<PushData> getPushData(UpExgMsgHistoryLocation data, SendMgrHandler sendMgrHandler) {

        byte[] body = sendMgrHandler.jt809Encode.UpExgMsgHistoryLocation(data,Jt809MsgIdConfig.UP_EXG_MSG_HISTORY_LOCATION);
        PushData pushData = new PushData(Jt809MsgIdConfig.UP_EXG_MSG, body);

        List<PushData> pushs = new ArrayList<>();
        pushs.add(pushData);
        return pushs;
    }

    /**
     * 数据转换
     * 补发车辆定位信息 上级平台无需应答
     * @param positionInfo
     * @param basicVehicleInfo
     */
    @Override
    public UpExgMsgHistoryLocation convert(GpsData positionInfo, BasicVehicleInfo basicVehicleInfo) {
        UpExgMsgHistoryLocation upExgMsgHistoryLocation = new UpExgMsgHistoryLocation();
        upExgMsgHistoryLocation.setBasicVehicleInfo(basicVehicleInfo);
        upExgMsgHistoryLocation.setGnssCnt(1);
        List<GnssData> gnssDataList = new ArrayList<>();
        gnssDataList.add(GpsConvert.gnssDataHandle(positionInfo));
        upExgMsgHistoryLocation.setGnssDataList(gnssDataList);
        logger.info("补传数据：{}，{}",upExgMsgHistoryLocation.getBasicVehicleInfo().vehicleNo, gnssDataList.get(0).toString());
        return upExgMsgHistoryLocation;
    }

}
